﻿public class Solution128
{
    public int LongestConsecutive(int[] nums)




    {
        Console.WriteLine("hashList: " + nums);

        //先创建一个哈希表

        int[] hashList = new int[2000000001];
        int listLen = hashList.Length / 2;

        Console.WriteLine(listLen);

        for (int i = 0; i < nums.Length; i++)
        {
            hashList[nums[i] + listLen] = 1;
        }


        // 在这里实现 LongestConsecutive() 的逻辑

        int curentLength = 0;//当前最长的序列
        int betterLength = 0;//当前最长的序列

        //判断过的数字放入哈希表
        //判断current+1在不在数组
        foreach (int num in hashList)
        {
            //Console.WriteLine(num);


            if (num == 1)
            {

                curentLength++;
            }
            else
            {
                if (curentLength > betterLength)
                {
                    betterLength = curentLength;
                }


                curentLength = 0;
            }
        }


        return betterLength;
    }
}



class Program128
{
    static void Main128(string[] args)
    {
        Solution128 solution = new Solution128();
        int[] nums = { 0, 1, 2, 4, 8, 5, 6, 7, 9, 3, 55, 88, 77, 99, 999999999 }; // 你可以根据需要修改 nums 的值

        int longest = solution.LongestConsecutive(nums);
        Console.WriteLine("Longest consecutive sequence length: " + longest);

        Console.WriteLine("Press any key to exit...");
        Console.ReadKey();
    }
}